﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace csharpTransforms2js
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    [System.Runtime.InteropServices.ComVisibleAttribute(true)]
    public partial class MainWindow : Window
    {

        public MainWindow()
        {
            InitializeComponent();
        }
        private void WebBrowser_Loaded(object sender, RoutedEventArgs e)
        {
            //加载网页
            webBrowser1.Navigate(Environment.CurrentDirectory + @"\index.html");
            //关键语句
            webBrowser1.ObjectForScripting = new MyScriptObject(this);
        }
    }

    public class MyScriptObject
    {
        private MainWindow _form;
        private string outString="testText";
        public MyScriptObject(MainWindow form)
        {
            _form = form;
        }

        //调用C#方法
        public void Test(string message)
        {
            MessageBox.Show(outString);
            MessageBox.Show(message, "client code");
        }

        //网页方法
        public string text(string message)
        {
            return message;
        }
    }
}
